package com.tmxk.days01.carrental_wmh;

/**
 * 汽车租赁管理类(RentMgrSys)对业务数据进行测试
 * @author Administrator
 *
 */
public class RentMgrSys01 {
    static MotoVehicle[] motoVehicles  = new MotoVehicle[12];
    /**
     * 初始化机动车信息
     */
	/*static{
		// 1. 初始化四条 轿车信息对象
		// 多态： 父类对象指向子类具体实例
		MotoVehicle car1 = new Car("京NY28588", "宝马", 800, "X6");
		MotoVehicle car2 = new Car("京CNY3284", "宝马", 600, "550i");
		MotoVehicle car3 = new Car("京NT37465", "别克", 300, "林荫大道");
		MotoVehicle car4 = new Car("京NT96968", "别克", 600, "GL8");
		//MotoVehicle[] cars = new MotoVehicle[] { car1, car2, car3, car4 };

		// 2. 初始化四条 客车信息对象
		MotoVehicle bus1 = new Bus("京6566754", "金杯", 800, 16);
		MotoVehicle bus2 = new Bus("京8696997", "金龙", 800, 16);
		MotoVehicle bus3 = new Bus("京9696996", "金杯", 1500, 34);
		MotoVehicle bus4 = new Bus("京8696998", "金龙", 1500, 34);
		//MotoVehicle[] buses = { bus1, bus2, bus3, bus4 };

		// 3. 初始化四条 卡车信息对象
		MotoVehicle truck1 = new Truck("京MH98725", "一汽解放", 50, 1);
		MotoVehicle truck2 = new Truck("京3216L59", "重庆红岩", 50, 1);
		MotoVehicle truck3 = new Truck("京NU98631", "一汽解放", 100, 2);
		MotoVehicle truck4 = new Truck("京CY56312", "重庆红岩", 100, 2);

		//通过数组下标赋值
		motoVehicles[0] = car1;
		motoVehicles[1] = car2;
		motoVehicles[2] = car3;
		motoVehicles[3] = car4;
		motoVehicles[4] = bus1;
		motoVehicles[5] = bus2;
		motoVehicles[6] = bus3;
		motoVehicles[7] = bus4;
		motoVehicles[8] = truck1;
		motoVehicles[9] = truck2;
		motoVehicles[10] = truck3;
		motoVehicles[11] = truck4;

	}*/

    public static void main(String[] args) {
        motoVehicles = initMotoVehicle02();
        // null操作任意属性和方法 就会报   java.lang.NullPointerException  空指针异常
        // 循环遍历
        for (MotoVehicle c : motoVehicles) {
            if ( c != null) {
                System.out.println(c.getBrand() + "\t"  + c.getVehicleId() + "\t" + c.getPerRent());
            }
        }
    }

    /**
     * 初始化机动车信息遍历方式一
     */
    public static void  initMotoVehicle01(){
        // 1. 初始化四条 轿车信息对象
        Car car1 = new Car("京NY28588", "宝马", 800, "X6");
        Car car2 = new Car("京CNY3284", "宝马", 600, "550i");
        Car car3 = new Car("京NT37465", "别克", 300, "林荫大道");
        Car car4 = new Car("京NT96968", "别克", 600, "GL8");
        Car[] cars = new Car[] { car1, car2, car3, car4 };

        // 2. 初始化四条 客车信息对象
        Bus bus1 = new Bus("京6566754", "金杯", 800, "16座");
        Bus bus2 = new Bus("京8696997", "金龙", 800, "16座");
        Bus bus3 = new Bus("京9696996", "金杯", 1500, "34座");
        Bus bus4 = new Bus("京8696998", "金龙", 1500, "34座");
        Bus[] buses = { bus1, bus2, bus3, bus4 };

        // 3. 初始化四条 卡车信息对象
        Truck truck1 = new Truck("京MH98725", "一汽解放", 50, "1吨");
        Truck truck2 = new Truck("京3216L59", "重庆红岩", 50, "1吨");
        Truck truck3 = new Truck("京NU98631", "一汽解放", 100, "2吨");
        Truck truck4 = new Truck("京CY56312", "重庆红岩", 100, "2吨");
        Truck[] trucks = { truck1, truck2, truck3, truck4 };

        for (Car c : cars) {
            System.out.println(c.getBrand() + "\t" + c.getType() + "\t" + c.getVehicleId() + "\t" + c.getPerRent());
        }

        for (Bus bus : buses) {
            System.out.println(bus);
        }

        for (Truck tuTruck : trucks) {
            System.out.println(tuTruck.getBrand() + "\t" + tuTruck.getTonnage() + "\t" + tuTruck.getVehicleId() + "\t" + tuTruck.getPerRent());
        }
    }


    /**
     * 初始化机动车信息遍历方式二
     */
    public static MotoVehicle[] initMotoVehicle02(){
        // 1. 初始化四条 轿车信息对象
        // 多态： 父类对象指向子类具体实例
        MotoVehicle car1 = new Car("京NY28588", "宝马", 800, "X6");
        MotoVehicle car2 = new Car("京CNY3284", "宝马", 600, "550i");
        MotoVehicle car3 = new Car("京NT37465", "别克", 300, "林荫大道");
        MotoVehicle car4 = new Car("京NT96968", "别克", 600, "GL8");
        //MotoVehicle[] cars = new MotoVehicle[] { car1, car2, car3, car4 };

        // 2. 初始化四条 客车信息对象
        MotoVehicle bus1 = new Bus("京6566754", "金杯", 800, "16座");
        MotoVehicle bus2 = new Bus("京8696997", "金龙", 800, "16座");
        MotoVehicle bus3 = new Bus("京9696996", "金杯", 1500, "34座");
        MotoVehicle bus4 = new Bus("京8696998", "金龙", 1500, "34座");
        //MotoVehicle[] buses = { bus1, bus2, bus3, bus4 };

        // 3. 初始化四条 卡车信息对象
        MotoVehicle truck1 = new Truck("京MH98725", "一汽解放", 50, "1吨");
        MotoVehicle truck2 = new Truck("京3216L59", "重庆红岩", 50, "1吨");
        MotoVehicle truck3 = new Truck("京NU98631", "一汽解放", 100, "2吨");
        MotoVehicle truck4 = new Truck("京CY56312", "重庆红岩", 100, "2吨");

        MotoVehicle[] motoVehicles  = { car1, car2, car3,  car4, bus1, bus2, bus3, bus4,truck1, truck2, truck3, truck4 };

        return motoVehicles;

    }
}

